﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Collections;
using System.Data;
using CE.Database;

/// <summary>
/// Summary description for CreditCardDetailsDB
/// </summary>
/// 
namespace CE.CreditCard
{
    public class CreditCardDetailsDB
    {
        public CreditCardDetailsDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public Int64 Insert(CreditCardDetails ccdetails)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocCCDetaisInsertUpdateSingleItem";

            SortedList _sPara = new SortedList();

            _sPara.Add("@CCId", ccdetails.CCId);
            _sPara.Add("@CCClass", ccdetails.CCClass);
            _sPara.Add("@FinancialInstitute", ccdetails.FinancialInstitute);
            _sPara.Add("@ProductName", ccdetails.ProductName);
            _sPara.Add("@CCImage", ccdetails.CreditcardImage);
            _sPara.Add("@CCStatus", ccdetails.CreditCardStatus);
            _sPara.Add("@CCType", ccdetails.CreditCardType);

            _sPara.Add("@AnualIncomeLocal", ccdetails.AnualIncomeLocal);
            _sPara.Add("@AnualIncomeForeigner", ccdetails.AnualIncomeForeigner);
            _sPara.Add("@MinimumofAge", ccdetails.MinimumAge);
            _sPara.Add("@MaximumofAge", ccdetails.MaximumAge);

            _sPara.Add("@BalanceTransfer", ccdetails.BalanceTransfer);
            _sPara.Add("@BalanceTransDuration", ccdetails.BalanceTransDuration);
            _sPara.Add("@IntrestRatePurchase", ccdetails.IntrestRatePurchase);
            _sPara.Add("@PurchaseRateDuration", ccdetails.PurchaseRateDuration);
            _sPara.Add("@IntrestRateCash", ccdetails.IntrestRateCash);

            _sPara.Add("@AnualFee", ccdetails.AnualFee);
            _sPara.Add("@SupplementaryFee", ccdetails.SupplementFee);
            _sPara.Add("@LatePayCharge", ccdetails.LatepayCharge);
            _sPara.Add("@MinimumCharge", ccdetails.MinimumCharge);
            _sPara.Add("@MinimumMonthlyRepay", ccdetails.MinMonthlyRepay);
            _sPara.Add("@CashAdvWidthdrawCharge", ccdetails.CashAdvWdrawCharge);
            _sPara.Add("@Dollersign", ccdetails.Doller == true ? 1 : 0);
            _sPara.Add("@Percentagesign", ccdetails.Percentage == true ? 1 : 0);
            _sPara.Add("@CashAdvFinanceCharge", ccdetails.CashAdvFinCharge);

            _sPara.Add("@FeeWaiver", ccdetails.FeeWaiver == true ? 1 : 0);
            _sPara.Add("@FeeWaiverDuration", ccdetails.FeeWaiverDuration);
            _sPara.Add("@WelcomeGift", ccdetails.WelcomeGift == true ? 1 : 0);
            _sPara.Add("@RewardPoint", ccdetails.RewardPoint == true ? 1 : 0);
            _sPara.Add("@RewardPointExpiry", ccdetails.RewardPointExpiry);
            _sPara.Add("@RewardsPrivileges", ccdetails.RewardsPrivileges);
            _sPara.Add("@FreeInsurance", ccdetails.FreeInsurance == true ? 1 : 0);
            _sPara.Add("@IntrestFreeDays", ccdetails.IntrestFreeDays);
            _sPara.Add("@DestinationMiles", ccdetails.DestinationMiles == true ? 1 : 0);
            _sPara.Add("@DestinationMilesDuration", ccdetails.DestMilesDur);
            _sPara.Add("@Status", ccdetails.Status == true ? 1 : 0);

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public CreditCardDetails GetCCDetails(Int64 CCId)
        {
            CreditCardDetails _ccdetails = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocCCDetaisSelectItemList";

            SortedList _spara = new SortedList();
            _spara.Add("@CCId", CCId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _ccdetails = new CreditCardDetails();
                    _ccdetails = FillDataRecord(_dt, 0);
                }
            }
            return _ccdetails;
        }

        private CreditCardDetails FillDataRecord(DataTable myDataTable, int RowId)
        {
            CreditCardDetails myCCDetails = new CreditCardDetails();
            myCCDetails.CCId = Convert.ToInt64(myDataTable.Rows[RowId]["CCId"].ToString());
            myCCDetails.FinancialInstitute = Convert.ToInt32(myDataTable.Rows[RowId]["FinancialInstitute"].ToString());
            myCCDetails.CCClass = Convert.ToInt32(myDataTable.Rows[RowId]["CCClass"].ToString());
            myCCDetails.ProductName = myDataTable.Rows[RowId]["ProductName"].ToString();
            myCCDetails.CreditcardImage = myDataTable.Rows[RowId]["CCImage"].ToString();
            myCCDetails.CreditCardStatus = Convert.ToInt32(myDataTable.Rows[RowId]["CCStatus"].ToString());
            myCCDetails.CreditCardType = Convert.ToInt32(myDataTable.Rows[RowId]["CCType"].ToString());

            myCCDetails.AnualIncomeLocal = Convert.ToSingle(myDataTable.Rows[RowId]["AnualIncomeLocal"].ToString());
            myCCDetails.AnualIncomeForeigner = Convert.ToSingle(myDataTable.Rows[RowId]["AnualIncomeForeigner"].ToString());
            myCCDetails.MinimumAge = Convert.ToInt32(myDataTable.Rows[RowId]["MinimumofAge"].ToString());
            myCCDetails.MaximumAge = Convert.ToInt32(myDataTable.Rows[RowId]["MaximumofAge"].ToString());

            myCCDetails.BalanceTransfer = Convert.ToSingle(myDataTable.Rows[RowId]["BalanceTransfer"].ToString());
            myCCDetails.BalanceTransDuration = Convert.ToInt32(myDataTable.Rows[RowId]["BalanceTransDuration"].ToString());
            myCCDetails.IntrestRatePurchase = Convert.ToSingle(myDataTable.Rows[RowId]["IntrestRatePurchase"].ToString());
            myCCDetails.PurchaseRateDuration= Convert.ToInt32(myDataTable.Rows[RowId]["PurchaseRateDuration"].ToString());
            myCCDetails.IntrestRateCash = Convert.ToSingle(myDataTable.Rows[RowId]["IntrestRatePurchase"].ToString());

            //myCCDetails.AnualFee = Convert.ToSingle(myDataTable.Rows[RowId]["AnualFee"].ToString());
            //myCCDetails.SupplementFee = Convert.ToSingle(myDataTable.Rows[RowId]["SupplementaryFee"].ToString());
            myCCDetails.AnualFee = myDataTable.Rows[RowId]["AnualFee"].ToString();
            myCCDetails.SupplementFee = myDataTable.Rows[RowId]["SupplementaryFee"].ToString();
            myCCDetails.LatepayCharge = Convert.ToSingle(myDataTable.Rows[RowId]["LatePayCharge"].ToString());
            myCCDetails.MinimumCharge = Convert.ToSingle(myDataTable.Rows[RowId]["MinimumCharge"].ToString());
            myCCDetails.MinMonthlyRepay = Convert.ToSingle(myDataTable.Rows[RowId]["MinimumMonthlyRepay"].ToString());
            myCCDetails.CashAdvWdrawCharge = Convert.ToSingle(myDataTable.Rows[RowId]["CashAdvWidthdrawCharge"].ToString());
            myCCDetails.Doller = Convert.ToBoolean(myDataTable.Rows[RowId]["Dollersign"].ToString());
            myCCDetails.Percentage = Convert.ToBoolean(myDataTable.Rows[RowId]["Percentagesign"].ToString());
            myCCDetails.CashAdvFinCharge = Convert.ToSingle(myDataTable.Rows[RowId]["CashAdvFinanceCharge"].ToString());

            myCCDetails.FeeWaiver = Convert.ToBoolean(myDataTable.Rows[RowId]["FeeWaiver"].ToString());
            myCCDetails.FeeWaiverDuration = Convert.ToInt32(myDataTable.Rows[RowId]["FeeWaiverDuration"].ToString());
            myCCDetails.WelcomeGift = Convert.ToBoolean(myDataTable.Rows[RowId]["WelcomeGift"].ToString());
            myCCDetails.RewardPoint = Convert.ToBoolean(myDataTable.Rows[RowId]["RewardPoint"].ToString());
            myCCDetails.RewardPointExpiry = Convert.ToInt32(myDataTable.Rows[RowId]["RewardPointExpiry"].ToString());
            myCCDetails.RewardsPrivileges = myDataTable.Rows[RowId]["RewardsPrivileges"].ToString();
            myCCDetails.FreeInsurance = Convert.ToBoolean(myDataTable.Rows[RowId]["FreeInsurance"].ToString());
            myCCDetails.IntrestFreeDays = Convert.ToInt32(myDataTable.Rows[RowId]["IntrestFreeDays"].ToString());
            myCCDetails.DestinationMiles = Convert.ToBoolean(myDataTable.Rows[RowId]["DestinationMiles"].ToString());
            myCCDetails.DestMilesDur = Convert.ToInt32(myDataTable.Rows[RowId]["DestinationMilesDuration"].ToString());
            myCCDetails.Status = Convert.ToBoolean(myDataTable.Rows[RowId]["Status"].ToString());
            return myCCDetails;
        }

        public DataTable GetCCDetailsList(Int64 CCId)
        {
            DataTable _cclist = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocCCDetaisSelectItemList";

            SortedList _spara = new SortedList();
            _spara.Add("@CCId", CCId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _cclist = _dt;
                }
            }
            return _cclist;
        }

    }
}
